# -*- coding:utf-8 -*-
# @Time:2024/4/1921:01
# @Author:miuzg
# @FileName:new test2.py
# @Software:PyCharm

import time
from multiprocessing import Process
from threading import Thread


# 没啥意义单纯耗时间
def work():
    res = 1
    for i in range(1, 100000):
        res *= i


# 装饰器：获取运行时间
def get_time(fun):
    def calc_time(*args, **kwargs):
        start_time = time.time()
        res = fun(*args, **kwargs)
        end_time = time.time()
        print('执行时间为：', end_time - start_time, 's')
        return res

    return calc_time


@get_time
def faster_process():
    # 进程,把任务分给五个进程来执行 2.6642587184906006 s
    p_list = []
    for i in range(5):
        p = Process(target=work)
        p_list.append(p)
        p.start()

    for p in p_list:
        p.join()

@get_time
def faster_thread():
    t_list = []
    for i in range(5):
        t = Thread(target=work)
        t_list.append(t)
        t.start()

    for t in t_list:
        t.join()
    # 线程，把任务分成五个线程来做    10.618061304092407 s
if __name__ == '__main__':
    faster_process()
    faster_thread()
